package com.raju.backuppwds;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/user")
public class UserController {

	private static Logger logger = Logger.getLogger(UserController.class);

	@ModelAttribute("users")
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public List<User> listUsers() throws IOException {
		List<User> users = new ArrayList<User>();

		User user = new User();
		user.setId(10001);
		user.setEmail("user.one@gmail.com");
		user.setName("User UNO");

		users.add(user);

		return users;
	}

	@ModelAttribute("user")
	@RequestMapping(value = "/", method = RequestMethod.POST)
	public User saveUser(@RequestBody User user) throws IOException {
		logger.debug(user);
		return user;
	}
}